var app = getApp()
var adds = {};
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabindex: 0,
    tabpid:0,
    tabcid:0,
    proain: false,
    isshow: 1,
    showt: '展开',
    deparshow: false,
    communityListOne: [],
  },
  tabChose:function(e){
    var that = this;
    var index=e.currentTarget.dataset.index;
    that.setData({
      tabchoseStyle:index,
      tabcid:e.currentTarget.dataset.tabcid
    })
    that.getCategorysharelist();
  },
  departab: function (e) {
    var that = this;
    const tabindex = e.currentTarget.dataset.dex;
    console.log(tabindex);
    
    if(tabindex==0){
      var tabpid = 0;
    }else{
      var tabpid = e.currentTarget.dataset.pid;
    }
    console.log(tabpid)
    that.setData({
      tabindex: tabindex,
      tabpid:tabpid
    })
    that.getCategorysharelist();
  },
  opend: function () {
    if (this.data.isshow == 0) {
      this.setData({
        isshow: 1,
        showt: '展开'
      })
    } else {
      this.setData({
        isshow: 0,
        showt: '收起'
      })
    }
  },
  proaInfor: function () {
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/publicProblemsInfor/publicProblemsInfor',
    })
  },
  deparlist: function () {
    if (this.data.deparshow) {
      this.setData({
        deparshow: false
      })
    } else {
      this.setData({
        deparshow: true
      })
    }
  },
  departabs: function (e) {
    // console.log(e);
    const index = e.currentTarget.dataset.dex;
    
    this.setData({
      tabindex: index,
      deparshow: false
    })
  },
  scrolltoupper: function (e) {
    console.log(e);
  },
  toLike: function (a) {
    var e = this;
    let communityListOne = e.data.communityListOne;
    var n = a.currentTarget.dataset.index
    var a_id = a.currentTarget.dataset.a_id
    var openid = wx.getStorageSync('openid')
    if (communityListOne[n].dianzan == 0) {
      app.util.request({
        'url': 'entry/wxapp/share.userdianz',
        data: {
          parentid: a_id,
          openid: openid,
        },
        success: function (res) {
          console.log(res)

        }
      })
      wx.showToast({
        title: "点赞成功",
        icon: "none",
        duration: 1500,
        success: function () {
          var dianzan = "communityListOne[" + n + "].dianzan"
          console.log(dianzan)
          e.setData({
            [dianzan]: 1
          })
        }
      });

    } else {
      wx.showToast({
        title: "点赞是严肃的，不可以反悔哦！",
        icon: "none",
        duration: 1500
      });
    }
  },
  previewImage: function(a) {
    var t = this;
    console.log(a)
    var i = a.currentTarget.dataset.index;
    var url = a.currentTarget.dataset.url
    var artrs = a.currentTarget.dataset.data
    console.log(i, url, artrs)
    wx.previewImage({
      current: url,
      urls: artrs
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getShowcategory();
    console.log(options.index)
    if(options.index!=undefined){
      that.setData({
        tabindex:options.index,
        tabpic:options.tabpic,
      })
      app.util.request({
        url: 'entry/wxapp/share.Categorysharelist',
        data:{
          openid:wx.getStorageSync('openid'),
          tabindex:options.index,
          tabpid:options.tabpic,
          tabcid:0,
        },
        success: function(res) {
          console.log(res.data)
          that.setData({
            communityListOne: res.data,
          })
        }
      })
    }else{
      console.log("ssss");
      that.getCategorysharelist();
    }
  },

  getShowcategory:function(){
    var that = this
    app.util.request({
      url: 'entry/wxapp/share.Allcategory',
      success: function(res) {
        console.log(res.data)
        that.setData({
          depar: res.data,
        })
      }
    })
  },
  getCategorysharelist:function(){
    var that = this;
    var tabindex = that.data.tabindex;
    var tabpid = that.data.tabpid;
    var tabcid = that.data.tabcid;
    console.log(tabindex,tabpid,tabcid)
    app.util.request({
      url: 'entry/wxapp/share.Categorysharelist',
      data:{
        openid:wx.getStorageSync('openid'),
        tabindex:tabindex,
        tabpid:tabpid,
        tabcid:tabcid,
      },
      success: function(res) {
        console.log(res.data)
        that.setData({
          communityListOne: res.data,
        })
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})